<template>
  <div class="group-store">
    <div class="table-title">
      <el-input v-model="searchData.MultiSearch" style="width:220px;" placeholder="姓名、电话、订单号或房间号"></el-input>
      <el-select v-model="searchData.StoreId" placeholder="请选择酒店" style="position: relative;top: 1px;">
  			<el-option :label="'全部酒店'" :value="0"></el-option>
  			<el-option v-for="m in HotelList" :label="m.Name" :value="m.Id" :key="m.Id"></el-option>
  		</el-select>
      <el-select v-model="searchData.OrderStatus" placeholder="请选择房间状态" style="position: relative;top: 1px;">
				<el-option :label="'全部状态'" :value="-1"></el-option>
				<el-option :label="'已预订'" :value="'0'"></el-option>
				<el-option :label="'已入住'" :value="'1'"></el-option>
				<el-option :label="'部分入住'" :value="'2'"></el-option>
				<el-option :label="'已退房'" :value="'3'"></el-option>
				<el-option :label="'部分退房'" :value="'4'"></el-option>
				<el-option :label="'已取消'" :value="'5'"></el-option>
			</el-select>
      <el-select v-model="searchData.PaymentStatus" placeholder="请选择支付状态" style="position: relative;top: 1px;">
				<el-option :label="'全部支付状态'" :value="0"></el-option>
				<el-option :label="'欠款'" :value="1"></el-option>
				<el-option :label="'已支付'" :value="2"></el-option>
			</el-select>
      <div style="margin-top:20px">
        <el-select v-model="searchData.FromChannel" placeholder="渠道类型" @change="getFromChannel1(searchData.FromChannel)">
          <el-option :label="'全部渠道'" :value="0"></el-option>
          <el-option
            v-for="m in ChannelList"
            :label="m.Name"
            :value="parseInt(m.Code)"
            :key="m.Code">
          </el-option>
        </el-select>
        <el-select v-model="searchData.TravelAgency" placeholder="渠道商" filterable v-if="searchData.FromChannel==7||searchData.FromChannel==8">
          <el-option
            label="全部"
            :value="0"
            :key="0">
          </el-option>
          <el-option
            v-for="m in ChannelChildList"
            :label="m.Name"
            :value="parseInt(m.Code)"
            :key="m.Code">
          </el-option>
        </el-select>
        <el-date-picker
          v-model="dateTime"
          type="daterange"
          :editable="false"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="getDate">
        </el-date-picker>
  			<el-button type="primary" @click="initList" data-auth="bloc_order_query">查询</el-button>
  			<el-button type="primary" :disabled="!listData.length" @click="handleExcel" data-auth="bloc_order_export">导出</el-button>
      </div>
    </div>
    <div class="table-content">
      <el-table
        border
        :data="listData"
        style="width: 100%">
        <el-table-column
          label="酒店名称"
          prop="HotelName">
        </el-table-column>
        <el-table-column
          label="订单号"
          prop="OrderSerialid">
        </el-table-column>
        <el-table-column
          label="联系人">
          <template slot-scope="scope">
            <span>{{scope.row.ContactName||''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="入住日期">
          <template slot-scope="scope">
            <span>{{scope.row.MinCheckInDate.split('T')[0]||''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="金额"
          prop="HotelAllAmount">
          <template slot-scope="scope">
            <span>￥{{scope.row.AllAmount||''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="渠道">
          <template slot-scope="scope">
            <span>{{scope.row.FromChannel||''}}</span>
          </template>
        </el-table-column>
				<el-table-column
          label="间数">
          <template slot-scope="scope">
            <span>{{scope.row.RoomCount||''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单状态">
          <template slot-scope="scope">
            <span>{{scope.row.OrderStatusName||''}}</span>
          </template>
        </el-table-column>
				<el-table-column
          label="支付状态">
          <template slot-scope="scope">
            <span>{{scope.row.PaymentStatusName||''}}</span>
          </template>
        </el-table-column>
				<el-table-column
          label="备注" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{scope.row.Remark||''}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleShow(scope.$index, scope.row)">查看</el-button>
            <el-button
              size="mini"
              v-if="scope.row.NeedSetRoom&&scope.row.OrderStatusName==='已预订'"
              @click.stop="setRoom(scope.row.OrderSerialid)">分房</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="table-page">
			<el-pagination
			  background
				@size-change="changePage"
      	@current-change="getList"
      	:current-page.sync="searchData.pageIndex"
      	:page-sizes="[100, 200, 300, 400]"
			  layout="total,prev, pager, next"
			  :total="pageTotal">
			</el-pagination>
    </div>
    <time-line :showInfo="showInfo" :formData="formData" :title="'集团订单日志'" ref="tim"></time-line>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="roomShow"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      @close="initList"
      width="1360px"
      center>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
        <div class="user-title">客户信息</div>
        <div class="user-info">
          <el-form-item label="联系人：" size="mini" prop="ContactName">
            <el-autocomplete
              v-model="ruleForm.ContactName"
              :fetch-suggestions="querySearchAsync"
              placeholder="请输入内容"
              @select="val=>{ruleForm.ContactPhone=val.Phone}"
            ></el-autocomplete>
          </el-form-item>
          <el-form-item label="手机号：" size="mini" prop="ContactPhone">
            <el-input :maxlength="11" v-model="ruleForm.ContactPhone"></el-input>
          </el-form-item>
          <el-form-item label="来源渠道：" size="mini" label-width="95px" prop="FromChannel">
            <el-select v-model="ruleForm.FromChannel" placeholder="请选择" @change="getFromChannel1(ruleForm.FromChannel)">
              <el-option
                v-for="m in ChannelList"
                :label="m.Name"
                :value="parseInt(m.Code)"
                :key="m.Code">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="渠道商：" size="mini" label-width="80px" prop="TravelAgency" v-if="ruleForm.FromChannel==7||ruleForm.FromChannel==8">
            <el-select v-model="ruleForm.TravelAgency" filterable placeholder="请选择">
              <el-option
                v-for="m in ChannelChildList"
                :label="m.Name"
                :value="parseInt(m.Code)"
                :key="m.Code">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="销售员：" size="mini" label-width="80px" prop="SalesmanId">
              <el-select v-model="ruleForm.SalesmanId" placeholder="请选择" filterable>
                <el-option
                  label="无"
                  :value="0">
                </el-option>
                <el-option
                  v-for="m in SalesmanList"
                  :label="m.JobNo+'-'+m.Name"
                  :value="m.Id"
                  :key="m.Id">
                </el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="支付类型：" size="mini" label-width="95px" prop="PaymentMode">
              <el-select v-model="ruleForm.PaymentMode" placeholder="请选择">
                <el-option :label="'全额预付'" :value="1"></el-option>
                <el-option :label="'部分预付'" :value="2"></el-option>
                <el-option :label="'到店现付'" :value="3"></el-option>
                <el-option :label="'已担保（未支付）'" :value="4"></el-option>
              </el-select>
          </el-form-item>
        </div>
        <div class="room-form" v-if="!orderInfoData.HasArrangeRoom">
          <div class="room-row" v-for="(m,index) in dialogData">
            <el-form-item label="入住：" size="mini" label-width="60px" prop="startDate" class="date-form sdate" style="width:25%">
              {{m.startDate}}
            </el-form-item>
            <el-form-item label="离店：" size="mini" label-width="60px" prop="endDate" class="date-form edate" style="width:25%">
              {{m.endDate}}
            </el-form-item>
            <el-form-item label="共" label-width="15px" style="width:25%">
              {{m.Days}}晚
            </el-form-item>
            <span class="el-icon-circle-plus-outline"
            @click="addRoom">
            添加房间</span>
            <br/>
            <el-form-item label="房间：" label-width="60px" prop="roomId" style="width:200px">
              <el-select v-model="m.roomId" size="mini" placeholder="请选择" @change="getMroomData(m,index)">
                <el-option
                  v-for="n in roomNumData"
                  :key="n.roomId"
                  :label="n.roomName"
                  :value="n.roomId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="政策：" label-width="60px" prop="roomId" style="width:200px">
              <el-select v-model="m.PolicyId" size="mini" placeholder="请选择" @change="getroomPrice(m)" disabled>
                <el-option v-for="n in m.CategoryList" :label="n.PolicyName" :value="n.PolicyConfigId" :key="n.Id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="房间数：" label-width="80px" prop="RoomCount" style="width:250px">
              <el-input-number v-model="m.RoomCount" :min="1" @change="val=>{roomChange(val,m,dialogData,m)}" :max="m.AllRoom"></el-input-number>
            </el-form-item>
             <el-form-item label="价格：" label-width="60px" size="mini" prop="AllAmount">
               <el-input v-model="m.AllAmount" @change="getAllAmount"></el-input>
             </el-form-item>
             <span class="el-icon-remove-outline" v-if="dialogData.length>1&&m.Status!==1" @click="deleteRoomPro('dialogData',index)">删除房间</span>
          </div>
        </div>

        <div class="user-title" v-if="orderInfoData.HasArrangeRoom">
          房间信息 <span class="el-icon-circle-plus-outline"
          @click="addRoom">
          添加房间</span>
        </div>
        <div class="room-form" v-if="orderInfoData.HasArrangeRoom">
          <div class="room-row" v-for="(m,index) in dialogData">
            <el-form-item label="房间：" label-width="60px" prop="roomId">
              <el-select v-model="m.roomId" size="mini" placeholder="请选择" @change="val=>{getMroomDatas(m,val)}">
                <el-option
                  v-for="n in roomNumData"
                  :key="n.roomId"
                  :label="n.roomName"
                  :value="n.roomId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="房号：" label-width="60px" size="mini" prop="roomNum" class="w150">
              <el-select v-model="m.roomNum" placeholder="请选择" @change="val=>{getRoomId(m,val)}">
                <el-option
                  :label="'未排房'"
                  :value="''">
                </el-option>
                <el-option
                  v-for="n in m.roomData"
                  :key="n.RoomId"
                  :label="n.RoomName"
                  :value="n.RoomName">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="到达" size="mini" label-width="50px" prop="startDate" class="date-form sdate">
              <el-date-picker
                v-model="m.startDate"
                type="datetime"
                placeholder="到达时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                align="right"
                :learable="false"
                :editable="false"
                :clearable="false"
                :picker-options="startOptions"
                 @change="getendDate(m,index)"
                >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="离开" size="mini" label-width="50px" prop="endDate" class="date-form edate">
              <el-date-picker
                v-model="m.endDate"
                type="datetime"
                placeholder="离开时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                align="right"
                :learable="false"
                :editable="false"
                :clearable="false"
                :picker-options="endOptions"
                 @change="getMroomPrcie(m)">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="晚数：" label-width="80px" prop="Days" style="width:250px">
              <el-input-number v-model="m.Days" :min="1" @change="val=>{changeDays(val,m)}"></el-input-number>
            </el-form-item>
            <el-form-item label="房费：" label-width="60px" size="mini" prop="AllAmount">
              <el-input v-model="m.AllAmount" @change="getAllAmount"></el-input>
            </el-form-item>
            <div>
               <span class="el-icon-remove-outline" v-if="dialogData.length>1&&m.Status!==1" @click="deleteRoomPro('dialogData',index)">删除房间</span>
            </div>
          </div>
        </div>
        <div class="user-title remark-div">
          <el-form-item label="备注：" label-width="60px" prop="Remark">
            <el-input type="textarea" v-model="ruleForm.Remark"></el-input>
          </el-form-item>
        </div>
        <div class="price-div">
          <span>订单总金额：{{ruleForm.AllAmount}} 元</span>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" data-auth="bloc_order_modify" @click="orderInfoData.HasArrangeRoom?submitOrder1():submitOrder()">修改</el-button>
        <el-button @click="initList">取 消</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="'订单详情'"
      :visible.sync="orderInfo"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="850px"
      center>
      <div class="orderinfo-div">
        <div class="orderinfo-title">基本信息
          <a @click="SendSMS" href="javascript:void(0);" class="sendsms-span">发送短信</a>
        </div>
        <span>联系人： {{orderInfoData.ContactName}} </span>
        <span :title="orderInfoData.PhoneAttribution">
          联系电话： {{orderInfoData.ContactPhone}}({{orderInfoData.PhoneAttribution}})
        </span>
        <span>销售员： {{getSaleMan(orderInfoData.SalesmanId)}}</span>
        <span>支付类型： {{orderInfoData.PaymentModeName}}</span>
        <span>渠道来源： {{orderInfoData.FromChannelName}}</span>
        <span v-if="!!orderInfoData.TravelAgencyName">渠道商： {{orderInfoData.TravelAgencyName}}</span>
      </div>
      <div class="orderinfo-div">
        <div class="orderinfo-title">
          预定信息<span style="font-size:14px">（订单号：{{orderInfoData.OrderSerialid}}）</span>
        </div>
        <template  v-for="m in orderInfoData.RoomList">
          <span>入住：{{m.CheckInDate.split('T')[0]}}</span>
          <span>离店：{{m.CheckOutDate.split('T')[0]}}</span>
          <span>共{{getAlldate(m.CheckInDate,m.CheckOutDate).length-1}}晚</span>
          <span>房型：{{m.RoomCategoryName}}<i class="type" :class="{'room-book':m.Status===0,'room-in':m.Status===1}">{{orderTypeList[m.Status]}}</i></span>
          <span>房间数：{{m.RoomCount}}</span>
          <span>价格：<b>{{m.AllAmount}}元</b></span>
          <p v-for="n in m.Roomers">
            <span>入住人姓名： {{n.Name}}</span>
            <span>入住人{{cerList[n.CertType]}}：{{n.CertNo}}</span>
          </p>
        </template>
        <p v-for="m in orderInfoData.SingleProductOrders">
          <span>商品：{{m.ProductName}}（{{m.UnitPrice}}/{{m.Unit}}）</span>
          <span>数量：{{m.Quantity}}{{m.Unit}}</span>
          <span>价格：<b>{{m.AllAmount}}元</b></span>
        </p>
      </div>
      <div class="orderinfo-div">
        <div class="orderinfo-title">
          收银信息
        </div>
        <span>订单总额: <b>¥{{orderInfoData.AllAmount}}</b></span>
        <span style="width: 40%;">已收款：<b>¥{{orderInfoData.PaidAmount}}</b><template>（含押金：{{orderInfoData.DepositPayAmount?orderInfoData.DepositPayAmount:0}}）</template></span>
        <span style="width: 25%;">需补交：<b>¥{{orderInfoData.RestAmount}}</b></span>
        <span @click="getpriceData" style="cursor:pointer;color: #399be6;margin-left:10px;float: right;text-align:right">财务明细</span>
        <div style="padding:10px 20px 0px 0px;float: left;">
          <el-dropdown trigger="hover" placement="top" @command="addPriceInfo">
            <span class="el-dropdown-link">添加款项</span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="{type:1,name:'收款'}">收款</el-dropdown-item>
              <el-dropdown-item :command="{type:2,name:'商品'}">商品</el-dropdown-item>
              <el-dropdown-item :command="{type:3,name:'收押金'}">收押金</el-dropdown-item>
              <el-dropdown-item :command="{type:4,name:'退款'}">退款</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <el-table
          :data="tableData"
          style="width: 95%;margin:5px auto;max-height: 200px;overflow: auto;"
          v-show="tableShow">
          <el-table-column
            prop="CashierItem"
            label="项目">
            <template slot-scope="scope">
              {{CashierItem[scope.row.CashierItem]}}
            </template>
          </el-table-column>
          </el-table-column>
          <el-table-column
            prop="Amount"
            label="收款">
          </el-table-column>
          <el-table-column
            label="支付方式"
            prop="CashierChannelDes">
          </el-table-column>
          <el-table-column
            prop="Remark"
            label="财务备注">
          </el-table-column>
          <el-table-column
            prop="OperatorTimeView"
            label="操作时间">
            <template slot-scope="scope">
              <template v-if="!!scope.row.OperatorTimeView">{{scope.row.OperatorTimeView}}</template>
            </template>
          </el-table-column>
          <el-table-column
            prop="OperatorName"
            label="操作人">
          </el-table-column>
          <el-table-column
            label="操作"
            class="delete-td">
            <template slot-scope="scope">
              <span @click="deletePriceInfo(scope.row)" v-if="scope.row.IsValid" style="color:rgb(57, 155, 230);cursor:pointer;">删除</span>
              <span v-else style="color:red">已删除</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="orderinfo-div">
        <div class="orderinfo-title">
          备注
        </div>
        <p style="padding:0 15px;">{{orderInfoData.Remark}}</p>
      </div>
      <span slot="footer" class="dialog-footer">
        <template v-if="orderInfoData.OrderStatusName!=='已取消'">
          <el-button type="warning" size="mini" data-auth="bloc_order_modify" round @click="orderInfoData.HasArrangeRoom?hotelBook(orderInfoData.OrderSerialid):roomBook()">修改订单</el-button>
          <el-button type="warning" size="mini" round @click="deleteOrderShowBtn">取消订单</el-button>
        </template>
        <el-button type="warning" size="mini" round @click.stop="() => {formData.orderSerialid=orderInfoData.OrderSerialid;$refs.tim.toggleDiolag()}">订单日志</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="'取消订单'"
      :visible.sync="deleteOrderShow"
      width="350px"
      class="delete-dialog"
      center>
      <div class="">
        <p>该订单已收款 <span style="color:red">¥{{orderInfoData.PaidAmount}}</span> ，是否确认取消该订单？</p>
        <p>财务是否需要处理:
          <el-radio v-model="radio" :label="0">是</el-radio>
          <el-radio v-model="radio" :label="1">否</el-radio>
        </p>
      </div>
      <div class="">
        <span class="color:red">*</span>请选择取消订单的原因：
        <p>
          <el-radio v-model="CancelReason" label="客人预订未到">客人预订未到</el-radio>
          <el-radio v-model="CancelReason" label="客人取消预约">客人取消预约</el-radio>
          <el-radio v-model="CancelReason" label="满房拒单">满房拒单</el-radio>
          <el-radio v-model="CancelReason" label="调整房态">调整房态</el-radio>
          <el-radio v-model="CancelReason" label="重复订单">重复订单</el-radio>
          <el-radio v-model="CancelReason" label="其他">其他</el-radio>
        </p>
      </div>
      <el-form :model="priceForm" :rules="pricerules" ref="priceForm" label-width="100px" v-if="radio===0">
        <el-form-item label="退款金额：" prop="Amount">
          <el-input v-model="priceForm.Amount"></el-input>
        </el-form-item>
        <el-form-item label="支付方式：" prop="CashierChannel">
          <el-select v-model="priceForm.CashierChannel" placeholder="请选择">
            <el-option
              v-for="m in CashierChannelList"
              :label="m.Name"
              :value="parseInt(m.Code)"
              :key="m.Code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="财务备注：" prop="Remark">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="priceForm.Remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="deleteOrder('priceForm')">保存</el-button>
        <el-button @click="deleteOrderShow = false">取 消</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="priceTitle"
      :visible.sync="priceShow"
      width="350px"
      center>
      <el-form :model="priceForm" :rules="pricerules" ref="priceForm" label-width="100px">
        <el-form-item label="金额：" prop="Amount">
          <el-input v-model="priceForm.Amount" ref="priceFormAmount"></el-input>
        </el-form-item>
        <el-form-item label="支付方式：" prop="CashierChannel">
          <el-select v-model="priceForm.CashierChannel" placeholder="请选择">
            <el-option
              v-for="m in CashierChannelList"
              :label="m.Name"
              :value="parseInt(m.Code)"
              :key="m.Code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="财务备注：" prop="Remark">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="priceForm.Remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="!roomShow" type="primary" @click="addPriceBtn('priceForm')">保存</el-button>
        <el-button v-else type="primary" @click="addPriceRoomIn('priceForm')">保存</el-button>
        <el-button @click="priceShow = false">取 消</el-button>
      </span>
    </el-dialog>

    <el-dialog
      :title="'分房'"
      :visible.sync="setRoomShow"
      width="550px"
      class="setRoom-dialog"
      center>
        <div class="setroom-div">
          <span>订单号：{{orderSerialid}}</span>
        </div>
        <div class="setroom-div" v-for="m in setRoomData">
          <div class="setroom-title">
            <span>{{m.RoomCategoryName}}</span>
            <span>{{m.Price}}</span>
            <span>{{m.RoomCount}}间</span>
          </div>
          <div class="setroom-title">
            <span>房态：</span>
            <span>
              <el-radio-group v-model="m.roomType" @change="setcheck(m.roomType)">
                <el-radio :label="0">全部</el-radio>
                <el-radio :label="1">脏房</el-radio>
                <el-radio :label="2">净房</el-radio>
              </el-radio-group>
          </span>
          </div>
          <div class="setroom-room">
            <span>房号：</span>
            <span>
              <el-checkbox-group v-model="m.checkList" @change="getcheckList(m.checkList,m.RoomCount)">
                <template v-for="n in m.RoomList">
                  <el-checkbox v-if="n.IsDirty" v-show="m.roomType===0||m.roomType===1" :label="n.RoomId" :key="n.RoomId">{{n.RoomNo}}</el-checkbox>
                  <el-checkbox v-if="!n.IsDirty" v-show="m.roomType===0||m.roomType===2" :label="n.RoomId" :key="n.RoomId">{{n.RoomNo}}</el-checkbox>
                </template>
              </el-checkbox-group>
            </span>
          </div>
        </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" :disabled="setRoomData.every(val=>{return !val.checkList.length})" @click="OrderSetRoom">保存</el-button>
        <el-button @click="setRoomShow = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :title="'发送短信'"
      :visible.sync="SMSShow"
      width="550px"
      class="delete-dialog"
      center>
      <el-form :model="SMSData" :rules="SMSrules" ref="SMSForm" label-width="120px">
        <el-form-item label="手机号码：" prop="Mobiles">
          <el-input v-model="SMSData.Mobiles" maxlength="11"></el-input>
        </el-form-item>
        <el-form-item label="短信内容：" prop="Content">
          <el-input v-model="SMSData.Content" type="textarea" rows="6"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="SendSMTrue">发送</el-button>
        <el-button @click="SMSShow = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data () {
      let _this=this;
      return {
        SMSShow:false,
        SMSData:{
          Mobiles:'',
          Content:''
        },
        SMSrules:{
          Mobiles: [
            { required: true, message: '请输入手机号', trigger: 'blur' },
          ],
          Content: [
            { required: true, message: '请输入短信内容', trigger: 'blur' },
          ],
        },
        showInfo:true,
        formData:{
          orderSerialid : ''
        },
        HotelId:0,
        pageTotal:0,
        dateTime:[],
        searchData:{
          StoreId:0,
          OrgId:JSON.parse(sessionStorage.getItem('nowmenu')).Id,
					MultiSearch:'',
          IsBlocOrder:true,
          FromChannel:0,
          TravelAgency:0,
          pageIndex:1,
          pageSize:10,
          StartDate:'',
          EndDate:'',
          DateType:'0',
          OrderStatus:-1,
          PaymentStatus:0,
        },
        HotelList:[],
				radio:1,
        CancelReason:'',
        CashierItem:{1:'房费',2:'商品',3:'押金',4:'退款'},
        paymentList:{1:'待支付',2:'支付中',3:'已支付'},
        cerList:{1:'身份证',2:'护照',3:'军官证',4:'通行证',5:'其他'},
        orderTypeList:['已预订','已入住','部分入住','已退房','部分退房','已取消'],
        orderCount:{assign:0,checkin:0,checkout:0,in:0},
        roomoutShow:false,
        roominShow:false,
        tableShow:false,
        priceShow:false,
        roomShow:false,
        orderInfo:false,
        deleteOrderShow:false,
        dialogTitle:'',
        priceTitle:'',
        dialogData:[],
        RoomCategoryIds:[],
        SalesmanList:[],
        ChannelList:[],
        ChannelChildList:[],
        orderInfoData:{},
        orderSerialid:'',
        OrderAction:1,
        priceForm:{
          Amount:'',
          Remark:'',
          CashierChannel:'',
        },
        pricerules:{
          Amount: [
            { required: true, message: '请输入金额', trigger: 'blur' },
          ],
          Remark: [
            { required: false, message: '', trigger: 'blur' },
          ],
          CashierChannel: [
            { required: true, message: '请选择支付方式', trigger: 'change' },
          ],
        },
        roominData:[],
        roomoutData:{
          OrderSerialid:'',
          HotelOrderIds:[],
          Remark:''
        },
        ruleForm: {
          ContactName: '',
          ContactPhone: '',
          FromChannel: '',
          SalesmanName: '',
          Remark:'',
          AllAmount:'',
          SellingPriceAmount:'',
          SalesmanId:0,
					PaymentMode:''
        },
        rules: {
          ContactName: [
            { required: true, message: '请输入联系人', trigger: 'blur' },
          ],
          ContactPhone: [],
          FromChannel: [
            { required: true, message: '请选择来源渠道', trigger: 'change' },
          ],
          TravelAgency: [
            { required: true, message: '请选择渠道商', trigger: 'change' },
          ],
          SalesmanId: [],
          PaymentMode: [
            { required: true,type:'number',message: '请选择支付类型', trigger: 'change' },
          ]
        },
        weekday:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
        startOptions: {
          disabledDate(time) {
            if(_this.OrderAction===2){
              return Date.now()>(time.getTime()+ 3600 * 1000 * 24 * 1)||Date.now()<time.getTime();
            }else if(_this.OrderAction===0){
              return false;
            }
            else{
              return Date.now()>(time.getTime()+ 3600 * 1000 * 24 * 1);
            }
          }
        },
        endOptions: {
          disabledDate(time) {
            if(_this.OrderAction===2){
              return Date.now()>(time.getTime()+ 3600 * 1000 * 24 * 1);
            }else if(_this.OrderAction===0){
              return false;
            }else{
              return Date.now()>time.getTime();
            }
          }
        },
        roomNumData:[],
        roomRowData:[
          {roomName:'101',roomId:'6',roomList:[
            {roomIn:0,price:'150'},
          ]}
        ],
        roomRowFormatData:[],
        orderData:[
          {room:'001',roomNum:'101',date:this.$format('yyyy-MM-dd',new Date()),name:'客户来源',day:1,type:'订单状态',personName:'客户姓名1'},
        ],
        nowDate: this.$format('yyyy-MM-dd',new Date()),
        selectedRoom:[],
        selectedCol:[],
        showCardList:[],
        ProductList:[],
        tableData:[],
        CashierChannelList:[],
        listData:[],
        setRoomShow:false,
        HotelOrderData:[],
        setRoomData:[],
      }
    },
    created(){
      this.$ajax.GetStoreList().then(res=>{
        if(res.Success&&res.Data){
          this.HotelList=res.Data
        }
      })
      this.$ajax.PayTypes().then(res=>{
        if(res.Success){
          this.CashierChannelList=res.Data;
        }
      })
      this.$ajax.GetUserListByOrgId({orgId:23}).then(res=>{
        if(res.Success){
          this.SalesmanList=res.Data;
          this.$ajax.Channels().then(res=>{
            if(res.Success){
              this.ChannelList=res.Data;
            }
          })
        }
      })
      this.initList();
    },
    methods:{
			getDate(date){
        if(!date){
          this.searchData.StartDate=''
          this.searchData.EndDate=''
          this.dateTime=[];
          return;
        }
        if(this.searchData.StartDate===this.$format('yyyy-MM-dd',new Date(date[0])) && this.searchData.EndDate===this.$format('yyyy-MM-dd',new Date(date[1])))return;
        this.searchData.StartDate=this.$format('yyyy-MM-dd',new Date(date[0]))
        this.searchData.EndDate=this.$format('yyyy-MM-dd',new Date(date[1]))
      },
      getSaleMan(id){
        let name=''
        this.SalesmanList.forEach(val=>{
          if(val.Id==id){
            name=val.Name
          }
        })
        return name
      },
      initRoom(){
        this.roomoutShow=false;
        this.roominShow=false;
        this.tableShow=false;
        this.priceShow=false;
        this.roomShow=false;
        this.orderInfo=false;
        this.deleteOrderShow=false;
        this.getList();
      },
      initList(){
        console.log(this.searchData)
        this.searchData.pageIndex=1;
        this.roomShow=false;
        this.roomColShow=false;
        this.getList();
      },
      changePage(size){
        this.searchData.pageIndex=1;
        this.searchData.pageSize=size;
        this.getList();
      },
      getList(){
        this.$ajax.GetBaseOrderByPage(this.searchData).then(res=>{
          if(res.Success){
            this.listData=res.Data.PagedData;
            this.pageTotal=res.Data.TotalCount;
          }
        })
      },
      handleExcel(){
        let data=_.cloneDeep(this.searchData);
        data=this.$urlEncode(data);
        window.open(this.$api.GetBaseOrderByPageToExcel+'?'+data);
			},
      resetForm(formName) {
        if(!this.$refs[formName]){return};
        this.$refs[formName].resetFields();
      },
			getDays(index){
        return new Date(new Date(this.nowDate).getTime() + 3600 * 1000 * 24 * index).getDay();
      },
      getFormatDay(index){
        return new Date(new Date(this.nowDate).getTime() + 3600 * 1000 * 24 * index);
      },
      isToday(index){
        return this.$format('MM-dd',new Date())===this.$format('MM-dd',this.getFormatDay(index));
      },
      getStartEnd(arr){

      },
      getAlldate(start,end){
        let bd = new Date(start),be = new Date(end);
        let bdTime = bd.getTime(), beTime = be.getTime(),timeDiff = beTime - bdTime;
        let dArr = [];
        for(var i=0; i<= timeDiff; i+=86400000){
          var ds = this.$format('yyyy-MM-dd',new Date(bdTime+i));
          dArr.push(ds)
        }
        return dArr
      },
			showBtn(type){
        let now=this.$format('yyyy-MM-dd',new Date());
        let yestoday=this.$format('yyyy-MM-dd',new Date(new Date(this.nowDate).getTime() - 3600 * 1000 * 24));
        switch (type) {
          case 0:
            return this.selectedRoom.every((val)=>{return val.date>=now})
            break;
          case 1:
            return this.selectedRoom.some((val)=>{return val.date==now||val.date==yestoday})
            break;
          case -1:
            return this.selectedRoom.some((val)=>{return val.date<now})
            break;
          default:
            return true
        }
      },
      continueDays(arr_days) {
        // 先排序，然后转时间戳
        let days = arr_days.sort().map((d, i) => {
          let dt = new Date(d)
          dt.setDate(dt.getDate() + 4 - i) // 处理为相同日期

          // 抹去 时 分 秒 毫秒
          dt.setHours(0)
          dt.setMinutes(0)
          dt.setSeconds(0)
          dt.setMilliseconds(0)

          return +dt
        })

        let ret = true

        days.forEach(d => {
          if (days[0] !== d) {
            ret = false
          }
        })

        return ret
      },
      roomIn(){
        let ret = false;
        _.map(this.showCardList,(val)=>{
          val.dateList=[]
          _.map(this.selectedRoom,(room)=>{
            if(val.roomNum===room.roomNum){
              val.dateList.push(room.date)
            }
          })
          val.dateList=val.dateList.sort();
          if(!val.dateList.some(val=>{return val.indexOf(this.$format('yyyy-MM-dd',new Date()))>=0})){
            ret=true;
          }
        })
        if(ret||!this.showCardList.every(val=>{return this.continueDays(val.dateList)})){
          this.$confirm('未来日期不可直接入住', {
            showConfirmButton:false,
            showCancelButton:false,
            callback:()=>{},
            type:'warning'
          })
          return;
        }
        this.clearRuleForm();
        this.dialogData=this.getDialogRoomData(_.sortBy(this.selectedRoom, ['roomNum', 'date']));
        this.dialogTitle='直接入住';
        this.OrderAction=2;
        this.showAddRoom();
      },
      getDialogRoomData(data){
        let finData=[];
        let obj={};
        let getdd=(date)=>{return this.$format('yyyy-MM-dd',new Date(new Date(date).getTime() - 3600 * 1000 * 24))};
        let getend=(date)=>{return this.$format('yyyy-MM-dd',new Date(new Date(date).getTime() + 3600 * 1000 * 24))};
        data.forEach((val)=>{
          val.startDate=val.CheckInDate;
          val.endDate=val.CheckOutDate;
          val.roomId=val.RoomCategoryId;
          val.PolicyId=val.RoomCategoryPolicyId;
          finData.push({...val})
        })
        return finData;
      },
      roomBook(){
        this.dialogData=[];
        this.clearRuleForm();
        this.ruleForm={...this.orderInfoData};
        this.dialogData=this.getDialogRoomData(this.ruleForm.RoomList);
        this.dialogTitle='修改订单';
        this.OrderAction=1;
        this.$ajax.GetRoomCategoryList({hotelId:this.orderInfoData.HotelId}).then(res=>{
          if(res.Success&&res.Data){
            this.roomNumData=[];
            _.map(res.Data,val=>{
              this.roomNumData.push({
                roomName:val.Name,
                isopen:true,
                roomId:val.Id,
                roomData:val.RoomNos
              })
            })
            _.map(this.dialogData,(val,index)=>{
              val.CategoryList=[];
              this.$ajax.getpolicylist({roomCategoryId:val.RoomCategoryId,hotelId:val.HotelId}).then(res=>{
                if(res.Success){
                  val.CategoryList=res.Data;
                  this.$set(this.dialogData,index,{...val});
                }
              })
              this.showAddRoom();
            })
          }
        })
      },
      hotelBook(id){
        this.$ajax.getorderdetail({OrderSerialid:id}).then(res=>{
          if(res.Success){
            this.ruleForm=res.Data;
            this.dialogData=[];
            this.ProductList=[];
            _.map(this.ruleForm.HotelOrders,val=>{
              this.dialogData.push({
                roomName:val.RoomCategoryName,
                "PolicyName": val.RoomCategoryName,
                "PolicyId": val.RoomCategoryPolicyId,
                "HotelId": val.HotelId,
                "HotelName": val.HotelName,
                "roomId": val.RoomCategoryId,
                "Id":val.RoomId,
                "HotelOrderId":val.Id,
                "roomNum": val.RoomNo,
                "startDate": val.CheckInDate,
                "endDate": val.CheckOutDate,
                "Days": this.getAlldate(val.CheckInDate,val.CheckOutDate).length-1,
                "AllAmount": val.AllAmount,
                "PolicyPriceAmount": val.PolicyPriceAmount,
                Status:val.Status,
                "Roomers": val.Roomers
              })
            })
            this.dialogTitle='修改订单';
            this.OrderAction=0;
            _.map(this.ProductList,(val,index)=>{
              this.$ajax.GetSingleProductByType({type:val.ProductType,hotelId:val.HotelId}).then(res=>{
                if(res.Success){
                  this.$set(this.ProductList[index],'ProductNameList',res.Data)
                }
              })
            })
            this.getAllAmount();
            _.map(this.dialogData,(val,index)=>{
              let data={
                HotelOrderId:val.HotelOrderId||0,
                CheckInTime:val.startDate,
                CheckOutTime:val.endDate,
                RoomCategoryId:val.roomId,
                HotelId:val.HotelId
              }
              val.roomData=[];
              this.$ajax.GetAvailableRooms(data).then(res=>{
                if(res.Success){
                  val.roomData=res.Data;
                  this.$set(this.dialogData,index,val)
                }
              })
              return val;
            })
            this.$ajax.GetRoomCategoryList({hotelId:this.orderInfoData.HotelId}).then(res=>{
              if(res.Success&&res.Data){
                this.roomNumData=[];
                _.map(res.Data,val=>{
                  this.roomNumData.push({
                    roomName:val.Name,
                    isopen:true,
                    roomId:val.Id,
                    roomData:val.RoomNos
                  })
                })
              }
            })
            this.getFromChannel(this.ruleForm.FromChannel);
            this.$nextTick(()=>{
              this.showAddRoom();
            })
          }
        })
      },
      getFromChannel(id){
        if(id==7||id==8){
          _.map(this.ChannelList,val=>{
            if(val.Code==id){
              this.ChannelChildList=val.Childs
            }
          })
        }else{
          this.ChannelChildList=[];
        }
      },
      getFromChannel1(id){
        this.ruleForm.TravelAgency='';
        this.searchData.TravelAgency=0;
        if(id==7||id==8){
          _.map(this.ChannelList,val=>{
            if(val.Code==id){
              this.ChannelChildList=val.Childs
            }
          })
        }else{
          this.ChannelChildList=[];
        }
      },
      roomChange(val,data,m){
        let num=0;
        _.map(m,value=>{
          if(data.roomId===value.roomId){
            num+=(!value.RoomCount?0:value.RoomCount)
          }
        })
        if(num>data.AllRoom){
          this.$nextTick(()=>{
            data.RoomCount=val-1;
          })
        }
        this.getroomPrice(data);
      },
      getroomPrice(val){
        if(!val.PolicyId)return;
        let data={roomCategoryId:val.roomId,policyConfigId:val.PolicyId,rooms:val.RoomCount,date:val.startDate,days:val.Days===1?1:val.Days-1};
        this.$ajax.singlepolicyprice(data).then(res=>{
          if(res.Success){
            val.AllAmount=res.Data;
            val.PolicyPriceAmount=res.Data;
            this.getAllAmount();
          }
        },rej=>{
          val.AllAmount=0;
          val.PolicyPriceAmount=0;
        })
      },
      showAddRoom(){
        this.tableData=[];
        this.roomShow=true;
      },
      clearRuleForm(){
        this.ProductList=[];
        this.ruleForm={
          ContactName: '',
          ContactPhone: '',
          TravelAgency: '',
          SalesmanName: '',
          Remark:'',
          AllAmount:'',
          SellingPriceAmount:'',
          PaymentMode:3,
          FromChannel: !!this.ChannelList[0]?parseInt(this.ChannelList[0].Code):'',
          SalesmanId:0
        }
        !!this.$refs['ruleForm']?this.$refs['ruleForm'].resetFields():'';
      },
      getMroomData(val,index){
        this.$ajax.getpolicylist({roomCategoryId:val.roomId,hotelId:val.HotelId}).then(res=>{
          if(res.Success){
            _.map(this.roomNumData,(room)=>{
              if(room.roomId===val.roomId){
                val.RoomCategoryName=room.roomName;
              }
            })
            val.CategoryList=res.Data;
            this.$set(this.dialogData,index,val);
            this.getroomPrice(val);
          }
        })
      },
      getMroomDatas(m,nowcheck){
        m.roomNum='';
        let data={
          HotelOrderId:m.HotelOrderId||0,
          CheckInTime:m.startDate,
          CheckOutTime:m.endDate,
          RoomCategoryId:nowcheck,
          HotelId:m.HotelId
        }
        this.$ajax.GetAvailableRooms(data).then(res=>{
          if(res.Success){
            m.roomData=res.Data;
          }
        })
        _.map(this.roomNumData,(room)=>{
          if(room.roomId===m.roomId){
            m.roomName=room.roomName;
          }
        })
        this.getMroomPrcie(m)
      },
      getRoomId(m,val){
        _.map(m.roomData,value=>{
          if(value.RoomName==val){
            m.Id=value.RoomId
          }
        })
      },
      getendDate(m,index){
        m.endDate=this.$format('yyyy-MM-dd',new Date(new Date(m.startDate).getTime() + 3600 * 1000 * 24))+' 12:00:00'
        let data={
          HotelOrderId:m.HotelOrderId||0,
          CheckInTime:m.startDate,
          CheckOutTime:m.endDate,
          RoomCategoryId:m.roomId,
          HotelId:this.HotelId
        }
        this.$ajax.GetAvailableRooms(data).then(res=>{
          if(res.Success){
            if(!res.Data.some(item=>{return item.RoomName===m.roomNum})){
              m.roomNum='';
            }
            m.roomData=res.Data;
            this.$set(this.dialogData,index,m)
          }
        })
        this.getMroomPrcie(m);
      },
      changeDays(val,data){
        let enddate=this.$format('yyyy-MM-dd',new Date(new Date(data.startDate).getTime() + 3600 * 1000 * 24 * val))+' 12:00:00';
        data.endDate=enddate;
        this.getMroomPrcie(data);
      },
      getMroomPrcie(m){
        if(!m.PolicyId)return;
        if(m.endDate< m.startDate){
          m.startDate=this.$format('yyyy-MM-dd',new Date(new Date(m.endDate).getTime() - 3600 * 1000 * 24))+' 12:00:00'
        }
        m.Days=this.getAlldate(m.startDate,m.endDate).length-1;
        let data={roomCategoryId:m.roomId,policyConfigId:m.PolicyId,rooms:1,date:m.startDate.split(' ')[0],days:this.getAlldate(m.startDate,m.endDate).length-1};
        this.$ajax.singlepolicyprice(data).then(res=>{
          if(res.Success){
            this.ruleForm.AllAmount+=res.Data-m.AllAmount;
            this.ruleForm.SellingPriceAmount+=res.Data-m.AllAmount;
            m.AllAmount=res.Data;
            m.PolicyPriceAmount=res.Data;
          }
        })
      },
      GetSingleProductByType(data){
        data.ProductId="";
        data.UnitPrice="";
        data.AllAmount=0;
        data.SellingPriceAmount=0;
        this.getAllAmount();
        this.$ajax.GetSingleProductByType({type:data.ProductType,hotelId:this.HotelId}).then(res=>{
          if(res.Success){
            data.ProductNameList=res.Data;
          }
        })
      },
      getUnitPrice(data){
        data.UnitPrice='';
        _.map(data.ProductNameList,val=>{
          if(val.Id===data.ProductId){
            data.UnitPrice=val.UnitPrice;
            data.AllAmount=data.UnitPrice*data.Quantity;
            data.SellingPriceAmount=data.UnitPrice*data.Quantity;
            data.ProductName=val.Name;
            data.Unit=val.Unit;
          }
        })
        this.getAllAmount();
      },
      getAllAmount(){
        this.ruleForm.AllAmount=0;
        this.ruleForm.SellingPriceAmount=0;
        _.map(this.dialogData,val=>{
          this.ruleForm.AllAmount+=parseFloat(val.AllAmount);
          this.ruleForm.SellingPriceAmount+=parseFloat(val.PolicyPriceAmount);
        })
        _.map(this.ProductList,val=>{
          this.ruleForm.AllAmount+=parseFloat(val.AllAmount);
          this.ruleForm.SellingPriceAmount+=parseFloat(val.SellingPriceAmount);
        })
      },
      submitOrder(){
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
              let data={
                OrderAction: this.OrderAction,
                RoomList: [],
                ProductList: [],
                ...this.ruleForm
              }
              data.RoomList=[];
              _.map(this.dialogData,val=>{
                console.log(val);
                data.RoomList.push({
                  "Id":this.OrderAction===0?val.HotelOrderId:0,
                  "RoomCategoryName": val.RoomCategoryName,
                  "RoomCategoryPolicyId": val.PolicyId,
                  HotelId: this.ruleForm.HotelId,
                  HotelName: this.ruleForm.HotelName,
                  "RoomCategoryId": val.roomId,
                  "RoomId":val.Id,
                  "CheckInDate": val.startDate,
                  "CheckOutDate": val.endDate,
                  "Days": this.getAlldate(val.startDate,val.endDate).length-1,
                  PolicyPriceAmount:val.PolicyPriceAmount,
                  "AllAmount": val.AllAmount,
                  RoomCount:val.RoomCount
                })
              })
              _.map(this.ProductList,val=>{
                data.ProductList.push({
                  "Id":val.Id,
                  ...val
                })
              })
              this.$ajax.ChangeBlocOrder(data).then(res=>{
                if(res.Success){
                  this.$message.success('已修改!');
                  this.initList();
                  this.showOrder(res.Data);
                }
              })
              }
            }
          )
      },
      submitOrder1(){
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            let data={
              OrderAction: this.OrderAction,
              HotelId: this.orderInfoData.HotelId,
              HotelName: this.orderInfoData.HotelName,
              ContactName: this.ruleForm.ContactName,
              ContactPhone: this.ruleForm.ContactPhone,
              FromChannel: this.ruleForm.FromChannel,
              TravelAgency: this.ruleForm.TravelAgency,
              SalesmanId: this.ruleForm.SalesmanId,
              Remark: this.ruleForm.Remark,
              AllAmount: this.ruleForm.AllAmount,
              SellingPriceAmount: this.ruleForm.SellingPriceAmount,
              PaymentMode:this.ruleForm.PaymentMode,
              RoomList: [],
              ProductList: []
            }
            _.map(this.dialogData,val=>{
              data.RoomList.push({
                "Id":this.OrderAction===0?val.HotelOrderId:0,
                "RoomCategoryName": val.roomName,
                "RoomCategoryPolicyId": val.PolicyId,
                HotelId: this.orderInfoData.HotelId,
                HotelName: this.orderInfoData.HotelName,
                "RoomCategoryId": val.roomId,
                "RoomId":!val.roomNum?0:val.Id,
                "RoomNo": val.roomNum,
                "CheckInDate": val.startDate,
                "CheckOutDate": val.endDate,
                "Days": this.getAlldate(val.startDate,val.endDate).length-1,
                PolicyPriceAmount:val.PolicyPriceAmount,
                Status:val.Status,
                "AllAmount": val.AllAmount,
                "Roomers": val.Roomers
              })
            })
            _.map(this.ProductList,val=>{
              data.ProductList.push({
                "Id":val.Id,
                "ProductId": val.ProductId,
                "ProductType": val.ProductType,
                "UnitPrice": val.UnitPrice,
                "Unit": val.Unit,
                "Quantity": val.Quantity,
                "AllAmount": val.AllAmount,
                "ProductName":val.ProductName,
                "SellingPriceAmount": val.SellingPriceAmount
              })
            })
            if(this.OrderAction===0){
              data.OrderSerialid=this.ruleForm.OrderSerialid;
              data.Id=this.ruleForm.OrderId;
              this.$ajax.ChangeOrder(data).then(res=>{
                if(res.Success){
                  this.initRoom();
                  this.showOrder(res.Data);
                  this.roomShow=false;
                }
              })
            }else{
              this.$ajax.Orderplaceorder(data).then(res=>{
                if(res.Success){
                  this.initRoom();
                  if(!!this.tableData.length){
                    _.map(this.tableData,(val,index)=>{
                      let datas=_.cloneDeep(val);
                      datas.OrderSerialid=res.Data;
                      this.$ajax.savecashierrecord(datas).then(res=>{
                        if(res.Success&&index===this.tableData.length-1){
                          this.showOrder(datas.OrderSerialid);
                        }
                      })
                    })
                  }else{
                    this.showOrder(res.Data);
                  }
                  this.roomShow=false;
                }
              })
            }
          }
        })
      },
      showOrder(id){
        this.orderSerialid=id;
        this.$ajax.GetBlocOrderDetail({OrderSerialid:this.orderSerialid}).then(res=>{
          if(res.Success){
            this.orderInfoData=res.Data;
            this.orderInfo=true;
            this.tableShow=false;
            if(this.roomoutShow){
              this.roomoutShowBtn()
            }else if(this.roominShow){
              this.roominShowBtn()
            }else{
              this.roomoutShow=false;
              this.roominShow=false;
            }
          }
        })
      },
      deleteRoomPro(data,index){
        this[data].splice(index,1);
        this.getAllAmount();
      },
      getpriceData(){
        if(!this.tableShow){
          this.tableData=[];
          this.$ajax.getcashierrecords({orderSerialid:this.orderSerialid}).then(res=>{
            if(res.Success){
              this.tableData=res.Data;
              this.tableShow=true;
            }
          })
        }else{
          this.tableShow=false;
        }
      },
      addPriceInfo(command){
        this.priceTitle=command.name;
        this.priceForm={
          Amount:'',
          Remark:'',
          CashierChannel:this.priceTitle==="收款"?4:this.priceTitle==="收押金"?1:'',
          CashierItem:command.type,
          OrderSerialid:this.orderSerialid
        }
        this.priceShow=true;
        this.$nextTick(()=>{
          this.$refs.priceFormAmount.focus();
        })
      },
      addPriceRoomIn(formName){
        this.tableData.push(this.priceForm);
        this.priceShow=false;
        this.tableShow=true;
      },
      addPriceBtn(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$ajax.savecashierrecord(this.priceForm).then(res=>{
              if(res.Success){
                this.$message.success('收款成功!');
                this.$refs[formName].resetFields();
                this.priceShow=false;
                this.tableShow=false;
                this.showOrder(this.orderSerialid);
                this.getpriceData();
              }
            })
          } else {
            return false;
          }
        });
      },
      deletePriceInfo(data){
        this.$confirm(`确认删除该${this.CashierItem[data.CashierItem]}记录？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.$ajax.deleteordercashierrecord({Id:data.Id,Item:data.CashierItem}).then(res=>{
            if(res.Success){
              this.$message({
                type: 'success',
                message: '已删除!'
              });
              this.showOrder(this.orderSerialid);
              this.tableShow=false;
              this.getpriceData();
            }
          })
        }).catch(() => {
        });
      },
      deleteOrderShowBtn(){
        this.priceForm={
          Amount:'',
          Remark:'',
          CashierChannel:'',
          CashierItem:4,
          OrderSerialid:this.orderSerialid
        }
        this.deleteOrderShow=true;
      },
      deleteOrder(formName){
        if(!this.CancelReason){
          this.$message.error('请选择取消原因');
          return
        }
        let data={
          orderSerialid:this.orderSerialid,
          CancelReason:this.CancelReason
        }
        if(this.radio===0){
          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.$ajax.savecashierrecord(this.priceForm).then(res=>{
                if(res.Success){
                  this.$ajax.CancelOrder(data).then(res=>{
                    if(res.Success){
                      this.$message({
                        type: 'success',
                        message: '已取消!'
                      });
                      this.deleteOrderShow=false;
                      this.orderInfo=false;
                      this.initRoom();
                    }
                  })
                }
              })
            }else {
              return false;
            }
          });
        }else{
          this.$ajax.CancelOrder(data).then(res=>{
            if(res.Success){
              this.$message({
                type: 'success',
                message: '已取消!'
              });
              this.deleteOrderShow=false;
              this.orderInfo=false;
              this.initRoom();
            }
          })
        }
      },
			handleShow(index,data){
        this.showOrder(data.OrderSerialid);
        this.HotelId=data.HotelId;
			},
      setRoom(id){
        this.orderSerialid=id;
        this.$ajax.GetOrderForSetRoom({orderSerialId:id}).then(res=>{
          if(res.Success){
            this.setRoomData=res.Data.map(val=>{
              val.roomType=0;
              val.checkList=[];
              return val;
            })
            this.setcheck(0);
            this.setRoomShow=true;
          }
        })
      },
      setcheck(type){
        this.setRoomData.forEach(val=>{
          val.checkList=[];
          val.RoomList.forEach(item=>{
            switch (type){
              case 1:
              if(item.HotelOrderId>0&&item.IsDirty){
                val.checkList.push(item.RoomId)
              }
              break;
              case 2:
              if(item.HotelOrderId>0&&!item.IsDirty){
                val.checkList.push(item.RoomId)
              }
              break;
              default:
              if(item.HotelOrderId>0){
                val.checkList.push(item.RoomId)
              }
              break;
            }
          })
        })
      },
      getcheckList(val,count){
        if(val.length>count){
          val=val.splice(count,1);
        }
      },
      OrderSetRoom(){
        let data={
          OrderSerialId:this.orderSerialid,
          RoomIds:[]
        }
        this.setRoomData.forEach(val=>{
          data.RoomIds.push(...val.checkList);
        })
        this.$ajax.OrderSetRoom(data).then(res=>{
          if(res.Success){
            this.$message.success('分房成功!');
            this.setRoomShow=false;
            this.initRoom();
          }
        })
      },
      querySearchAsync(queryString, cb) {
        if(!queryString)return;
        this.$ajax.QueryMember({nameOrMobile:queryString}).then(res=>{
          if(res.Success){
            let data=res.Data.map(item=>{return {value:item.Value,Phone:item.Key}})
            cb(data);
          }
        })
      },
      SendSMS(){
        !!this.$refs['SMSForm']?this.$refs['SMSForm'].resetFields():'';
        this.$ajax.GetCheckInNoticeSMS({orderSerialId:this.orderInfoData.OrderSerialid}).then(res=>{
          if(res.Success){
            this.SMSData={
              Content:res.Data,
              Mobiles:this.orderInfoData.ContactPhone,
            }
            this.SMSShow=true;
          }
        })
      },
      SendSMTrue(){
        this.$refs['SMSForm'].validate((valid) => {
          if (valid) {
            let data={
              Mobiles:[this.SMSData.Mobiles],
              Content:this.SMSData.Content
            }
            this.$ajax.SendSMS(data).then(res=>{
              if(res.Success){
                this.$message.success('发送成功!');
                this.SMSShow=false;
              }
            })
          } else {
            return false;
          }
        });
      },
      addRoom(){
        let data={...this.dialogData[this.dialogData.length-1]};
        let roomIndex=data.roomData.findIndex(item=>{return item.RoomId===data.Id});
        data.roomNum=data.roomData[roomIndex+1]?data.roomData[roomIndex+1].RoomName:data.roomData[roomIndex].RoomName;
        data.Id=data.roomData[roomIndex+1]?data.roomData[roomIndex+1].RoomId:data.roomData[roomIndex].RoomId;
        data.HotelOrderId=0;
        this.dialogData.push(data);
        this.getAllAmount();
      }
    }
  }
</script>
